<?
session_start();
include("config.php");
if ($_SESSION['admin']!="OK")
{
	echo "<script language='javascript'>alert('Please log in!');window.location.href='login.php';</script>";
	exit;
}
else
{
	if ($_POST["actions"]=="1")
	{
		$titles=addslashes(trim($_POST["titles"]));
		if (empty($titles))
		{
			echo "<script language='javascript'>alert('Topic can not be empty!');history.go(-1);</script>";
			exit;
		}
		else
		{
			$conn=mysql_connect($host,$user,$password);
			mysql_select_db($db);
			mysql_query("SET NAMES UTF8");
			$query="update vote_title set title='".$titles."',options='".$_POST["choice"]."' where id='".$_POST["titleid"]."'";
			$result=mysql_query($query);
			echo "<script language='javascript'>alert('Topic updated Succeed!');history.go(-1);</script>";
		}
	}
	else
	{
		$conn=mysql_connect($host,$user,$password);
		mysql_select_db($db);
		mysql_query("SET NAMES UTF8");
		$query="select * from vote_title where id=".$_GET["id"];
		$result=mysql_query($query);
		$row = mysql_fetch_array($result);
?>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>Questionnaire Survey System Management</title> 
<link href="main.css" rel="stylesheet" type="text/css" />
</head> 
<body>
<div id=main>
	<div class=title>Modify Vote Topic</div>
	<div id="menu">
	<ul>
		<li><a href='admin.php'>Administraction</a></li>
		<li><a href="editadmin.php">Your Account</a></li>
		<li><a href="addtitle.php" class="top">Add vote topic</a></li>
		<li><a href="showvote.php" target="_blank">Vote result</a></li>
		<li><a href="javascript:$msg=confirm('Are u sure to clean the result?');$msg?window.location.href='clearResult.php':history.go(0);">Delete Result</a></li>
		<li><a href="loginout.php">Log out</a></li>
		<li><a href="index.php" target="_blank">Home</a></li>
	</ul>
	</div>
	<form action="" method="post" name="addtitle" id="addtitle">
		<div class=main1>
			<div class="user2">Vote Topic:<input type="text" name="titles" id="titles" value=<? echo stripslashes($row["title"]);?> size="100">no larger than 200</div>
			<div class=main1>
				<div class="user3">Set 'Single' or 'Multiple'
				<? 
					if ($row["options"]=="a")
					{
						echo "<input name='choice' type='radio' value='a' checked>Single";
						echo "<input type='radio' name='choice' value='b'>Multiple";
					}
					else
					{
						echo "<input name='choice' type='radio' value='a'>Single";
						echo "<input type='radio' name='choice' value='b' checked>Multiple";
					} 
				?>
				</div>
			</div>
			<div class=main1>
				<div class="submit3"><input name="submit" type="submit" value="submit" class="inputs"/>
				<input name="B2" type="reset" value="reset" class="inputs" />
				<input name="actions" type="hidden" id="actions" value="1">
				<input name="titleid" type="hidden" id="ids" value="<?=$_GET["id"];?>">
			</div>
		</div>
	</form>
<?
	}
} 
?> 
</div>
<br />
<center>CopyRight@FengYL</center>
</body>
</html>
